from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-24 14:02:02.168477
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 24, Mar, 2022
Time: 14:02:07
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.6663
Nobs: 605.000 HQIC: -49.0666
Log likelihood: 7283.66 FPE: 3.80121e-22
AIC: -49.3216 Det(Omega_mle): 3.27978e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.349458 0.066399 5.263 0.000
L1.Burgenland 0.107185 0.040449 2.650 0.008
L1.Kärnten -0.110579 0.021159 -5.226 0.000
L1.Niederösterreich 0.193360 0.084546 2.287 0.022
L1.Oberösterreich 0.119652 0.083353 1.435 0.151
L1.Salzburg 0.259114 0.042911 6.038 0.000
L1.Steiermark 0.037076 0.056645 0.655 0.513
L1.Tirol 0.102576 0.045707 2.244 0.025
L1.Vorarlberg -0.068084 0.040356 -1.687 0.092
L1.Wien 0.017529 0.074190 0.236 0.813
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.053309 0.142667 0.374 0.709
L1.Burgenland -0.038438 0.086910 -0.442 0.658
L1.Kärnten 0.042063 0.045463 0.925 0.355
L1.Niederösterreich -0.201870 0.181659 -1.111 0.266
L1.Oberösterreich 0.454345 0.179095 2.537 0.011
L1.Salzburg 0.283012 0.092200 3.070 0.002
L1.Steiermark 0.112738 0.121709 0.926 0.354
L1.Tirol 0.306045 0.098208 3.116 0.002
L1.Vorarlberg 0.026671 0.086711 0.308 0.758
L1.Wien -0.029056 0.159406 -0.182 0.855
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197766 0.033953 5.825 0.000
L1.Burgenland 0.089044 0.020683 4.305 0.000
L1.Kärnten -0.007118 0.010819 -0.658 0.511
L1.Niederösterreich 0.242703 0.043232 5.614 0.000
L1.Oberösterreich 0.159504 0.042622 3.742 0.000
L1.Salzburg 0.040150 0.021942 1.830 0.067
L1.Steiermark 0.027118 0.028965 0.936 0.349
L1.Tirol 0.081944 0.023372 3.506 0.000
L1.Vorarlberg 0.054205 0.020636 2.627 0.009
L1.Wien 0.116754 0.037936 3.078 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.117643 0.033946 3.466 0.001
L1.Burgenland 0.042831 0.020679 2.071 0.038
L1.Kärnten -0.012887 0.010817 -1.191 0.234
L1.Niederösterreich 0.172513 0.043224 3.991 0.000
L1.Oberösterreich 0.334650 0.042614 7.853 0.000
L1.Salzburg 0.099931 0.021938 4.555 0.000
L1.Steiermark 0.112363 0.028959 3.880 0.000
L1.Tirol 0.089329 0.023368 3.823 0.000
L1.Vorarlberg 0.060588 0.020632 2.937 0.003
L1.Wien -0.017229 0.037929 -0.454 0.650
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125141 0.063677 1.965 0.049
L1.Burgenland -0.044976 0.038791 -1.159 0.246
L1.Kärnten -0.045225 0.020292 -2.229 0.026
L1.Niederösterreich 0.137652 0.081080 1.698 0.090
L1.Oberösterreich 0.160020 0.079936 2.002 0.045
L1.Salzburg 0.284678 0.041152 6.918 0.000
L1.Steiermark 0.058481 0.054323 1.077 0.282
L1.Tirol 0.158130 0.043834 3.607 0.000
L1.Vorarlberg 0.097370 0.038702 2.516 0.012
L1.Wien 0.071697 0.071148 1.008 0.314
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.075913 0.049702 1.527 0.127
L1.Burgenland 0.025056 0.030278 0.828 0.408
L1.Kärnten 0.053231 0.015838 3.361 0.001
L1.Niederösterreich 0.191009 0.063286 3.018 0.003
L1.Oberösterreich 0.330293 0.062393 5.294 0.000
L1.Salzburg 0.035249 0.032120 1.097 0.272
L1.Steiermark 0.008574 0.042401 0.202 0.840
L1.Tirol 0.119707 0.034214 3.499 0.000
L1.Vorarlberg 0.065996 0.030208 2.185 0.029
L1.Wien 0.096840 0.055534 1.744 0.081
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172910 0.059941 2.885 0.004
L1.Burgenland 0.005029 0.036515 0.138 0.890
L1.Kärnten -0.065862 0.019101 -3.448 0.001
L1.Niederösterreich -0.105887 0.076323 -1.387 0.165
L1.Oberösterreich 0.205503 0.075246 2.731 0.006
L1.Salzburg 0.054803 0.038737 1.415 0.157
L1.Steiermark 0.247380 0.051135 4.838 0.000
L1.Tirol 0.501835 0.041262 12.162 0.000
L1.Vorarlberg 0.064257 0.036431 1.764 0.078
L1.Wien -0.077213 0.066974 -1.153 0.249
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160276 0.066483 2.411 0.016
L1.Burgenland -0.001679 0.040500 -0.041 0.967
L1.Kärnten 0.062791 0.021186 2.964 0.003
L1.Niederösterreich 0.168068 0.084653 1.985 0.047
L1.Oberösterreich -0.057443 0.083459 -0.688 0.491
L1.Salzburg 0.208401 0.042965 4.850 0.000
L1.Steiermark 0.139199 0.056717 2.454 0.014
L1.Tirol 0.057017 0.045765 1.246 0.213
L1.Vorarlberg 0.146953 0.040408 3.637 0.000
L1.Wien 0.119397 0.074284 1.607 0.108
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.390040 0.039139 9.966 0.000
L1.Burgenland -0.003908 0.023843 -0.164 0.870
L1.Kärnten -0.020864 0.012472 -1.673 0.094
L1.Niederösterreich 0.202299 0.049836 4.059 0.000
L1.Oberösterreich 0.230762 0.049132 4.697 0.000
L1.Salzburg 0.036705 0.025294 1.451 0.147
L1.Steiermark -0.015833 0.033389 -0.474 0.635
L1.Tirol 0.088986 0.026942 3.303 0.001
L1.Vorarlberg 0.051005 0.023788 2.144 0.032
L1.Wien 0.043820 0.043731 1.002 0.316
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036585 0.104050 0.169094 0.137573 0.097578 0.080042 0.032513 0.208303
Kärnten 0.036585 1.000000 -0.026592 0.131120 0.048948 0.084939 0.443772 -0.066806 0.089450
Niederösterreich 0.104050 -0.026592 1.000000 0.312481 0.119228 0.273082 0.067213 0.153672 0.292734
Oberösterreich 0.169094 0.131120 0.312481 1.000000 0.212653 0.295376 0.166678 0.136722 0.238363
Salzburg 0.137573 0.048948 0.119228 0.212653 1.000000 0.122866 0.092600 0.105013 0.124235
Steiermark 0.097578 0.084939 0.273082 0.295376 0.122866 1.000000 0.134355 0.107258 0.035737
Tirol 0.080042 0.443772 0.067213 0.166678 0.092600 0.134355 1.000000 0.064416 0.150597
Vorarlberg 0.032513 -0.066806 0.153672 0.136722 0.105013 0.107258 0.064416 1.000000 -0.004264
Wien 0.208303 0.089450 0.292734 0.238363 0.124235 0.035737 0.150597 -0.004264 1.000000